package com.xjy.spring.thrift.core;

import org.apache.thrift.TProcessor;
import org.apache.thrift.protocol.TBinaryProtocol;
import org.apache.thrift.server.THsHaServer;
import org.apache.thrift.server.TServer;
import org.apache.thrift.transport.TFramedTransport;
import org.apache.thrift.transport.TNonblockingServerSocket;
import org.apache.thrift.transport.TTransportException;

import com.xjy.spring.thrift.config.ThriftServerConfig;

// 待研究
@Deprecated
public class HsHaThriftServer extends AbstractThriftServer {

    @Override
    protected void startThriftServer(TProcessor tProcessor, ThriftServerConfig config) throws TTransportException {
        System.err.println("start server, type is  HsHa, config is " + config);
        TNonblockingServerSocket nonblockingServerSocket = new TNonblockingServerSocket(config.getPort());
        THsHaServer.Args hshaArgs = new THsHaServer.Args(nonblockingServerSocket);
        hshaArgs.processor(tProcessor);
        hshaArgs.transportFactory(new TFramedTransport.Factory());
        hshaArgs.protocolFactory(new TBinaryProtocol.Factory());
        // 线程池服务模型，使用标准的阻塞式IO，预先创建一组线程处理请求。
        TServer server = new THsHaServer(hshaArgs);
        // 此处会阻塞
        server.serve();
    }

    @Override
    protected void registerThriftServer(ThriftServerConfig config) {
        // TODO Auto-generated method stub

    }

}
